package com.ruralflow.rental.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruralflow.common.annotation.Log;
import com.ruralflow.common.core.controller.BaseController;
import com.ruralflow.common.core.domain.AjaxResult;
import com.ruralflow.common.enums.BusinessType;
import com.ruralflow.rental.domain.Rental;
import com.ruralflow.rental.service.IRentalService;
import com.ruralflow.common.utils.poi.ExcelUtil;
import com.ruralflow.common.core.page.TableDataInfo;

/**
 * 出租屋信息Controller
 * 
 * @author ruralflow
 * @date 2025-02-28
 */
@RestController
@RequestMapping("/rental/rental")
public class RentalController extends BaseController
{
    @Autowired
    private IRentalService rentalService;

    /**
     * 查询出租屋信息列表
     */
    @PreAuthorize("@ss.hasPermi('rental:rental:list')")
    @GetMapping("/list")
    public TableDataInfo list(Rental rental)
    {
        startPage();
        List<Rental> list = rentalService.selectRentalList(rental);
        return getDataTable(list);
    }

    /**
     * 导出出租屋信息列表
     */
    @PreAuthorize("@ss.hasPermi('rental:rental:export')")
    @Log(title = "出租屋信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Rental rental)
    {
        List<Rental> list = rentalService.selectRentalList(rental);
        ExcelUtil<Rental> util = new ExcelUtil<Rental>(Rental.class);
        util.exportExcel(response, list, "出租屋信息数据");
    }

    /**
     * 获取出租屋信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('rental:rental:query')")
    @GetMapping(value = "/{rentalId}")
    public AjaxResult getInfo(@PathVariable("rentalId") Long rentalId)
    {
        return success(rentalService.selectRentalByRentalId(rentalId));
    }

    /**
     * 新增出租屋信息
     */
    @PreAuthorize("@ss.hasPermi('rental:rental:add')")
    @Log(title = "出租屋信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Rental rental)
    {
        return toAjax(rentalService.insertRental(rental));
    }

    /**
     * 修改出租屋信息
     */
    @PreAuthorize("@ss.hasPermi('rental:rental:edit')")
    @Log(title = "出租屋信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Rental rental)
    {
        return toAjax(rentalService.updateRental(rental));
    }

    /**
     * 删除出租屋信息
     */
    @PreAuthorize("@ss.hasPermi('rental:rental:remove')")
    @Log(title = "出租屋信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{rentalIds}")
    public AjaxResult remove(@PathVariable Long[] rentalIds)
    {
        return toAjax(rentalService.deleteRentalByRentalIds(rentalIds));
    }
}
